package com.lieve.tomcat;

import java.lang.ref.WeakReference;

/**
 * @author sunlijiang
 * @date 2020/4/2
 */
public class WeakReferenceTest {
    public static void main(String[] args) {
        Object obj = new Object();
        WeakReference<Object> objectWeakReference = new WeakReference<>(obj);
        int i = 0;
        while(true) {
            if (objectWeakReference.get() != null) {
                System.out.println(i++);
            } else {
                System.out.println("objectWeakReference is collected");
                break;
            }
        }
    }
}
